﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using SDT.Model;
using SDT.Site.ViewModels;

namespace SDT.Site.Controllers
{
    public class CounterController : Controller
    {
        //
        // GET: /Counter/
        public SDTDataContext eDataContext = new SDTDataContext();
        [ChildActionOnly]
        public ActionResult Visited()
        {
            CounterViewModels c = new CounterViewModels();
            c.TotalVisited = eDataContext.Counters.Sum(e => e.Visited).Value;
            var y = eDataContext.Counters.Where(a => a.AddDate.Value.Day == DateTime.Now.AddDays(-1).Day &&
                    a.AddDate.Value.Month == DateTime.Now.Month &&
                    a.AddDate.Value.Year == DateTime.Now.Year).FirstOrDefault();
            c.Yesterday = y != null ? y.Visited : 0;
            return View(c);
        }

    }
}
